from launch import LaunchDescription
from launch_ros.actions import Node
# 封装终端指令相关类--------------
# from launch.actions import ExecuteProcess
# from launch.substitutions import FindExecutable
# 参数声明与获取-----------------
# from launch.actions import DeclareLaunchArgument
# from launch.substitutions import LaunchConfiguration
# 文件包含相关-------------------
# from launch.actions import IncludeLaunchDescription
# from launch.launch_description_sources import PythonLaunchDescriptionSource
# 分组相关----------------------
# from launch_ros.actions import PushRosNamespace
# from launch.actions import GroupAction
# 事件相关----------------------
# from launch.event_handlers import OnProcessStart, OnProcessExit
# from launch.actions import ExecuteProcess, RegisterEventHandler,LogInfo
# 获取功能包下share目录路径-------
# from ament_index_python.packages import get_package_share_directory
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from ament_index_python.packages import get_package_share_directory
import os
from launch.event_handlers import OnProcessStart, OnProcessExit
from launch.actions import ExecuteProcess, RegisterEventHandler,LogInfo



def generate_launch_description():
    t1_relay_launch = IncludeLaunchDescription(
        launch_description_source=PythonLaunchDescriptionSource(
            launch_file_path=os.path.join(
                get_package_share_directory("ap_gazebo_mavproxy_carto_pro"),
                "t1_relay_launch.py"
                )
            ),launch_arguments=[("backg_r","80")]
    )

    t2_launch = IncludeLaunchDescription(
        launch_description_source=PythonLaunchDescriptionSource(
            launch_file_path=os.path.join(
                get_package_share_directory("ap_gazebo_mavproxy_carto_pro"),
                "t2_launch.py"
                )
            ),launch_arguments=[("backg_g","80")]
    )
    # 假设 t1_launch 启动某个实际的节点，监听该节点的启动事件
    # 比如这里启动一个实际的进程 t1_node
    # t1_launch_node = ExecuteProcess(
        # cmd=["ros2", "launch", "ap_gazebo_mavproxy_carto_pro", "t1_relay_launch.py"],
        # name="t1_launch_node",
        # output="screen"
    # )
    # 注册事件处理器：当 mode_service 成功退出时启动 arm_service
    # t1_t2 = RegisterEventHandler(
        # OnProcessStart(
            # target_action=t1_launch_node,  # 监听 mode_service 节点
            # target_action=arm_service,  # 监听 mode_service 节点
            # on_start=[
                # 只有在 mode_service 正常退出(exit)时，才启动 arm_service
                # t2_launch
                # mode_service
            # ]
        # )
    # )

    return LaunchDescription([t1_relay_launch,t2_launch])
    # return LaunchDescription([t1_t2,t1_launch_node])

